package com.javaweb.secondhand_trading.common.utils;

import com.javaweb.secondhand_trading.entity.Order;
import java.util.Arrays;
import java.util.List;

public class ValidationUtils {

    // 允许的订单状态列表
    private static final List<String> VALID_STATUSES = Arrays.asList(
            "pending", "completed", "cancelled"
    );

    /**
     * 验证订单创建参数
     */
    public static void validateOrderCreation(Order order) {
        if (order == null) {
            throw new IllegalArgumentException("订单信息不能为空");
        }

        if (order.getProductId() == null) {
            throw new IllegalArgumentException("商品ID不能为空");
        }

        if (order.getBuyerId() == null) {
            throw new IllegalArgumentException("买家ID不能为空");
        }

        if (order.getSellerId() == null) {
            throw new IllegalArgumentException("卖家ID不能为空");
        }

        if (order.getPhone() == null || order.getPhone().trim().isEmpty()) {
            throw new IllegalArgumentException("联系电话不能为空");
        }
    }

    /**
     * 验证订单状态是否有效
     */
    public static void validateOrderStatus(String status) {
        if (status == null || status.trim().isEmpty()) {
            throw new IllegalArgumentException("状态不能为空");
        }

        if (!VALID_STATUSES.contains(status.toLowerCase())) {
            throw new IllegalArgumentException("无效的订单状态: " + status +
                    "。有效状态为: " + VALID_STATUSES);
        }
    }
}